package com.gxa.modules.payment.controller;

import com.gxa.modules.payment.entity.*;
import com.gxa.modules.payment.form.MeterCycleQueryTimeForm;
import com.gxa.modules.payment.form.MeterQueryNameForm;
import com.gxa.modules.payment.service.ChargeDropDownService;
import com.gxa.modules.payment.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "缴费管理下拉框 接口")
@RestController
public class ChargeDropDownController {

    @Autowired
    private ChargeDropDownService chargeDropDownService;

    @ApiOperation("收费项目 下拉框")
    @GetMapping("/item/queryItemAll")
    public Result<List<Item>> queryItemAll(){
        Result<List<Item>> r = Result.success();

        try{
            List<Item> items = this.chargeDropDownService.queryItemAll();
            return Result.success(items);
        } catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("收费方式 下拉框")
    @GetMapping("/method/queryMethodIdByName")
    public Result<List<Method>> queryMethodIdByName(){
        Result<List<Method>> r = Result.success();

        try{
            List<Method> methods = this.chargeDropDownService.queryMethodIdByName();
            return Result.success(methods);
        } catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("计量单位 下拉框")
    @GetMapping("/unit/queryUnitAll")
    public Result<List<Unit>> queryUnitAll(){
        Result<List<Unit>> r = Result.success();

        try{
            List<Unit> units = this.chargeDropDownService.queryUnitAll();
            return Result.success(units);
        } catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("计算精度 下拉框")
    @GetMapping("/accuracy/queryAccuracyAll")
    public Result<List<Accuracy>> queryAccuracyAll(){
        Result<List<Accuracy>> r = Result.success();

        try{
            List<Accuracy> units = this.chargeDropDownService.queryAccuracyAll();
            return Result.success(units);
        } catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("仪表选择 下拉框")
    @GetMapping("/meter/queryMeterCodeByName")
    public Result<List<MeterQueryNameForm>> queryMeterCodeByName(){
        Result<List<MeterQueryNameForm>> r = Result.success();

        try{
            List<MeterQueryNameForm> units = this.chargeDropDownService.queryMeterCodeByName();
            return Result.success(units);
        } catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("抄表周期 下拉框")
    @GetMapping("/meterCycle/queryMethodCycleIdByName")
    public Result<List<MeterCycleQueryTimeForm>> queryMethodCycleIdByName(){
        Result<List<MeterCycleQueryTimeForm>> r = Result.success();

        try{
            List<MeterCycleQueryTimeForm> units = this.chargeDropDownService.queryMethodCycleIdByName();
            return Result.success(units);
        } catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
}
